/*
package com.bupt.config;


import com.bupt.bean.Event;
import com.bupt.dao.EventRepository;
import com.bupt.service.PrimaryKeyService;
import lombok.SneakyThrows;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

@Component
public class ReadFileWithALG {

    public static String surroundings;

    @Value("${filepath}")
    public String filepath;


//    @Autowired
//    EventRepository eventRepository;

//    @Autowired
//    private PrimaryKeyService primaryKeyService;

    //@PostConstruct
    public void initialize()  {
        Thread thread = new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
//                while (true) {
//                    //读取某一路径下的文件
//                }
                System.out.println(filepath);
                long begin = System.currentTimeMillis();
//                File file = new File(filepath+":\\pro");
                File file = new File("e:\\pro");
                File[] fileArray= file.listFiles();
                //所有文件时间排序
                Arrays.sort(fileArray, new CompratorByLastModified());

                //遍历每个文件内容
                for(int i =0;i<fileArray.length;i++){
                    File f=fileArray[i];
                    //文件内容
                    StringBuffer stringBuffer = new StringBuffer();
                    //高效读取文件内容
                    LineIterator it = FileUtils.lineIterator(f, "UTF-8");
                    try {
                        while (it.hasNext()) {
                            //可能是文件不够大  没看出来快多少
                            stringBuffer.append(it.nextLine());
                        }
                    }

                    finally
                    { LineIterator.closeQuietly(it);}

                    //以，切割成数组  如果大于阀值   1.以流的方式写入其他路径下
                    //2.存表       3.删文件
                    String[] splitarr = stringBuffer.toString().split("[2][0][2][2][0][4]+");
//                    String[] split = stringBuffer.toString().split(",");
                    for (int x = 1; x <splitarr.length ; x++) {
                        String[] split = splitarr[x].split(",");

                        boolean writeboolean=false;
                        Integer lasternumer=0;
                        List<Integer> pointerList= new ArrayList<>();
                        List<Integer> valueList= new ArrayList<>();
                        for (int j = 1; j <split.length ; j++) {
                            if (Integer.valueOf(split[j])>200){
                                pointerList.add(j);
                                valueList.add(Integer.valueOf(split[j]));
                                writeboolean=true;
                                lasternumer=j;
                            }
                        }
                        if(writeboolean){

//                            for (int j = 0; j <valueList.size() ; j++) {
//                                Integer value = valueList.get(j);
//                                Integer pointer = pointerList.get(j);
//                                if(pointer-pointerList.get(j+1)<50){
//                                    //相邻比大小
//                                }
//                            }

                            //写文件
                            List<String> list = Arrays.asList(splitarr[x]);
//                            FileUtils.writeLines(new File("e:\\pronew\\202204"+split[0]), list);
                            FileUtils.writeLines(new File("e:\\pronew\\202204"), list);
                            System.out.println(lasternumer);
                            System.out.println(split[lasternumer]);
                            //存表
                            // TODO
//                            Event event = new Event();
//                            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
//                            Integer id = primaryKeyService.getPrimaryKey("ALARM_STRATEGY_ID");
//                            event.setEventId(id);
//                            event.setEventType(1);
//                            event.setCreatTime(timestamp);
//                            event.setDeviceId(1556);
//                            event.setDeviceChannelId(1283);
//                            event.setPosition(lasternumer+"米");
//                            event.setValue(split[lasternumer]);
//                            event.setStatus(1);
//                            event.setEventDesc("202204"+split[0]+"光纤第"+lasternumer+"米产生入侵告警");
//                            event.setLatitude("");
//                            event.setLongitude("");
//                            event.setErrorFlag(0);
//                            event.setChannelSectionId(1051);
//                            eventRepository.save(event);
                        }
                    }
                    //删文件
                    FileUtils.forceDelete(f);
                }
                long stop = System.currentTimeMillis();
                System.out.println(stop-begin);
            }
        });
        thread.start();
    }


//    @PostConstruct
//    public void initialize()  {
//        Thread thread = new Thread(new Runnable() {
//            @SneakyThrows
//            @Override
//            public void run() {
//                System.out.println(filepath);
//                while (true) {
//                long begin = System.currentTimeMillis();
////                File file = new File(filepath+":\\pro");
//                File file = new File("e:\\pro");
//                File[] fileArray = file.listFiles();
//                //所有文件时间排序
//                Arrays.sort(fileArray, new CompratorByLastModified());
//
//                //遍历每个文件内容
//                for (int i = 0; i < fileArray.length; i++) {
//                    File f = fileArray[i];
//                    //文件内容
//                    StringBuffer stringBuffer = new StringBuffer();
//                    //高效读取文件内容
//                    LineIterator it = FileUtils.lineIterator(f, "UTF-8");
//                    try {
//                        while (it.hasNext()) {
//                            //可能是文件不够大  没看出来快多少
//                            stringBuffer.append(it.nextLine());
//                        }
//                    } finally {
//                        LineIterator.closeQuietly(it);
//                    }
//
//                    //以，切割成数组  如果大于阀值   1.以流的方式写入其他路径下
//                    //2.存表       3.删文件
//                    String[] splitarr = stringBuffer.toString().split("[2][0][2][2][0][4]+");
////                    String[] split = stringBuffer.toString().split(",");
//                    for (int x = 1; x < splitarr.length; x++) {
//                        String[] split = splitarr[x].split(",");
//
//                        boolean writeboolean = false;
//                        Integer lasternumer = 0;
//                        for (int j = 1; j < split.length; j++) {
//                            if (Integer.valueOf(split[j]) > 200) {
//                                // System.out.println(split[j]);
//                                // System.out.println(j);
//                                //System.out.println(f.getName());
//                                writeboolean = true;
//                                lasternumer = j;
//                            }
//                        }
//                        if (writeboolean) {
//                            //写文件
//                            List<String> list = Arrays.asList(splitarr[x]);
//                            FileUtils.writeLines(new File("e:\\pronew\\202204" + split[0]), list);
//                            //存表
//                            // TODO
//                            Event event = new Event();
//                            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
//                            Integer id = primaryKeyService.getPrimaryKey("ALARM_STRATEGY_ID");
//                            event.setEventId(id);
//                            event.setEventType(1);
//                            event.setCreatTime(timestamp);
//                            event.setDeviceId(1556);
//                            event.setDeviceChannelId(1283);
//                            event.setPosition(lasternumer + "米");
//                            event.setValue(split[lasternumer]);
//                            event.setStatus(1);
//                            event.setEventDesc("202204" + split[0] + "光纤第" + lasternumer + "米产生入侵告警");
//                            event.setLatitude("");
//                            event.setLongitude("");
//                            event.setErrorFlag(0);
//                            event.setChannelSectionId(1051);
//                            eventRepository.save(event);
//                        }
//                    }
//                    //删文件
//                    FileUtils.forceDelete(f);
//                }
//                long stop = System.currentTimeMillis();
//                System.out.println(stop - begin);
//            }
//        }
//        });
//        thread.start();
//    }

    public static void main(String[] args) {
        List<Integer> pointerList= new ArrayList<>();
        ArrayList<Integer> valueList= new ArrayList<>();
        valueList.add(99);   pointerList.add(3);
        valueList.add(98);   pointerList.add(4);
        valueList.add(100);  pointerList.add(5);
        valueList.add(2);    pointerList.add(666);
        valueList.add(3);    pointerList.add(667);
        valueList.add(2);    pointerList.add(669);
        valueList.add(95);   pointerList.add(1111);
        valueList.add(93);   pointerList.add(2222);
        valueList.remove(3);
//        for (int j = 0; j <valueList.size() ; j++) {
//            Integer value = valueList.get(j);
//            Integer pointer = pointerList.get(j);
//            if(pointer-pointerList.get(j+1)<50){
//                if(value<valueList.get(j)){
//
//                }
//                //相邻比大小
//            }
//        }
        for (int i = 0; i <pointerList.size() ; i++) {
            //for (int j = 0; j <pointerList.size() ; j++) {
            if (i < pointerList.size()-1) {

            if (Math.abs(pointerList.get(i) - pointerList.get(i + 1)) < 50) {
                //System.out.println(pointerList.get(i));
            } else {
                System.out.println(pointerList.get(i));

            }
        }
           // }
        }

        new ReadFileWithALG().initialize();
    }

    static class CompratorByLastModified implements Comparator<File> {
        public int compare(File f1, File f2) {
            long diff = f1.lastModified() - f2.lastModified();
            if (diff < 0)
                return -1;//倒序正序控制
            else if (diff == 0)
                return 0;
            else
                return 1;//倒序正序控制
        }
    }

}
*/
